package org.jrfe.gfx;

import org.lwjgl.opengl.GL11;

public abstract class JRFEXRenderer extends JRFERenderer {

	protected static int ptype;
	protected static int elements;
	
	public static void mapVertexBatchData(VertexBatch vset){
		ptype = vset.getPtype();
		elements = vset.getPtype();
	}
	
	public static void mapVertexBatchVertexes(VertexBatch vset){
		GL11.glVertexPointer(2, 0, vset.getVertexs());
	}
	
	public static void mapVertexBatchColors(VertexBatch vset){
		GL11.glColorPointer(4, 0, vset.getColors());		
	}
	
	public static void mapVertexBatchTexCords(VertexBatch vset){
		GL11.glTexCoordPointer(2, 0, vset.getTexCords());
	}
	
	
	public static void bindTextrue(int textureID){
		// See if Vertex Batch is using texture
		if (textureID != 0) {
			// VertexBatch is using texture

			// Cheak if cullrently binded texute is not VertexBatch texture
			if (activeTex != textureID) {
				// Need to bind VertexBatch texture

				// if last texture was no texture enable texture states
				if (activeTex == 0) {
					//System.out.println("Test");
					GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
					GL11.glEnable(GL11.GL_TEXTURE_2D);
				}

				// Bind Vertex Batch texture
				GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

				// Set activeTexture to VertexBatch texture
				activeTex = textureID;
			}

		} else {
			// VertexBatch has no texture
			// Check if current activeTexture is texture not 0
			if (activeTex != 0) {
				// Current active texture is texture disable texture states and
				// unbind currently active texture
				GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
				GL11.glDisable(GL11.GL_TEXTURE_2D);
				GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
				activeTex = 0;
			}
		}
	}
	
	public static void renderMappedVertexBatch(){
		GL11.glDrawArrays(ptype, 0, elements);
	}
	
	
	
	
}
